import { createRouter, createWebHashHistory } from 'vue-router'
import useStore from '@/store'

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/home',
      component: () => import('@/views/HomeView.vue'),
    },
    {
      path: '/category',
      component: () => import('@/views/Category.vue'),
    },
    {
      path: '/recommend',
      component: () => import('@/views/Recommend.vue'),
    },
    {
      path: '/shoppingcart',
      // component: () => import('@/views/Shopping_cart.vue'),
      component: () => location.href = 'https://m.you.163.com/u/login?callback=https%3A%2F%2Fm.you.163.com%2Fucenter'
    },
    {
      path: '/mine',
      component: () => import('@/views/Mine.vue'),   
      // component: () => location.href = 'https://m.you.163.com/u/login?callback=https%3A%2F%2Fm.you.163.com%2Fucenter'
    },
    {
      path: "/search",
      component: () => import("@/views/Search.vue")
    },
    {
      name: "xiangqing",
      path: "/detail/:id",
      component: () => import("@/views/Detail.vue")
    },
    {
      path: "/",
      redirect: "/home"
    }
  ]
})
const arr = ["xiangqing"];
router.beforeEach(function (to, from) {
  // 进行tabbar状态开关的控制
  const store = useStore();
  // 根据在不在数组中来决定tabbar是开还是关
  store.$state.isTabBarShow = arr.indexOf(to.name as string) === -1
})


export default router
